<?php 
include_once('connection/connection.php');
//session_start();
//ob_start();
include('header.php');
include('menu.php');
include('config.php');
$rows_num = $_SESSION['rows_num'];
$arrHabSource_reserv = $_SESSION['arrSource_reserv'];
$sum_reserv = $_SESSION['totalsum_reserv'];
$loc_id = $_SESSION['loc_id'];
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="css/style_question.css" type="text/css" rel="stylesheet" />
<script language="javascript" type="text/javascript" src="js/validate.js"></script>
<title>UFW Form</title>
</head>
<body>
<?php
if(isset($_POST['submit']))
{
		$fclick = true;
		$i=1;
		foreach($arrHabSource_reserv as $key=>$val)
		{
			for($j=1; $j<=$val; $j++)
			{
			$hname='habitation_name'.$i;
			$type_reserv='type_reserv'.$i;
			$type_habit='type_habit'.$i;
			$status_reserv='status_reserv'.$i;
			$storege_cap='storege_cap'.$i;
			
			$hname=$_POST[$hname];
			$type_reserv=$_POST[$type_reserv];
			$type_habit=$_POST[$type_habit];
			$status_reserv=$_POST[$status_reserv];
			$storege_cap=$_POST[$storege_cap];
			
			$qr1="INSERT INTO tbl_dtls_ufw_reserv_detail(loc_id, habitation_name, type_habit, type_reserv, status_reserv, storage_cap) VALUES ('$loc_id', '$hname', '$type_habit', '$type_reserv', '$status_reserv', '$storege_cap')"; 
		 	//echo $qr1;
			$result1=mysql_query($qr1);
			$i++;
		}
		}		
		if($result1)
		{
			//echo "success2";
			$relocatePage=true;	
			}
			else 
			{
				$errorIns="Error inserting detail_reserv table <br>";
			}
			if($errorIns==0) 
			{
				header('Location: ufw_5.php');
			}
			else 
			{ 
				echo $errorIns;exit;
			}
}		
else
{
	$fclick = false;
	$flag=0;
}		
?>
<div align="center">
<form action="" method="post" enctype="multipart/form-data" name="ufw_4" id="ufw_4" onSubmit="return ufw4()">
	<table border="0" width="800" id="table1" cellspacing="0" cellpadding="0">
		<tr>
			<td height="16">
			<p align="center">
			<font face="Verdana" style="font-size: 10pt; font-weight: 700" color="#000000">
			UFW</font></p></td>
		</tr>
		<tr>
			<td height="14">
			<p align="center">
			<font style="font-size: 8.5pt" face="Arial" color="#000000">Page 4 </font></p></td>
		</tr>
		
		<tr>
			<td bgcolor="#C5D8EB" height="30"><span style="font-weight: 700">
			<font face="Arial" style="font-size: 8.5pt" color="#000000">&nbsp;&nbsp;Asset Details</font></span></td>
		</tr>
		<tr>
			<td>
			<table border="0" width="100%" id="table4" cellspacing="1" cellpadding="0" bgcolor="#FDF9EE">
				<tr>
					<td colspan="14"><span style="font-size: 4pt">&nbsp;</span></td>
				</tr>
				<tr>
							<td width="180" height="32" align="center" bgcolor="#F7E6B7">
							<font style="font-size: 8.5pt" face="Verdana" color="#990000">
							Type of reservoir</font></td>
							<td bgcolor="#F7E6B7" align="center" width="182" rowspan="0">
		 			  <font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Habitation Name</font></td>
					  <td align="center" width="95" rowspan="0" bgcolor="#F7E6B7">
						<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">
					  Type MH/ OH</font></td>
							<td height="32" width="117" align="center" bgcolor="#F7E6B7">
							<font style="font-size: 8.5pt" face="Verdana" color="#990000">
							Status of reservoirs</font></td>
							<td height="32" width="172" align="center" bgcolor="#F7E6B7">
							<font style="font-size: 8.5pt" face="Verdana" color="#990000">
							Storage capacity (KLD)</font></td>
							<!--<td height="32" width="74" align="center" bgcolor="#F7E6B7">
							<font style="font-size: 8.5pt" face="Verdana" color="#990000">
							current total requirement (KLD) as per 40 lpcd</font></td>
							<td height="32" width="70" align="center" bgcolor="#F7E6B7">
							<font style="font-size: 8.5pt" face="Verdana" color="#990000">
							Drinking demand (KLD) as per 10 lpcd</font></td>
							<td height="32" align="center" bgcolor="#F7E6B7">
							<font style="font-size: 8.5pt" face="Verdana" color="#990000">
							Other demand (KLD) as per 30 lpcd</font></td>
							<td height="32" align="center" width="70" bgcolor="#F7E6B7">
							<font style="font-size: 8.5pt" face="Verdana" color="#990000">
							Total projected demand (KLD) 40 lpcd</font></td>
							<!--<td width="70" align="center" bgcolor="#F7E6B7">
							<font style="font-size: 8.5pt" face="Verdana" color="#990000">
							Quantity lost by illegal connection (KL)</font></td>
							<td width="70" align="center" bgcolor="#F7E6B7">
							<font style="font-size: 8.5pt" face="Verdana" color="#990000">
							Quantity lost by leakage &amp; wastage (KL)</font></td>
							<td width="70" align="center" bgcolor="#F7E6B7">
							<font style="font-size: 8.5pt" face="Verdana" color="#990000">
							UFW (KLD)</font></td>
							<td height="32" align="center" width="89" bgcolor="#F7E6B7">
							<font style="font-size: 8.5pt" face="Verdana" color="#990000">Remark</font></td>-->
			  </tr>
						
						<?php
						$qr="Select * from tbl_dtls_ufw_num_pump_reserv where loc_id='$loc_id' order by habitation_code";
						$result=mysql_query($qr);
						$i=0;
						while($row=mysql_fetch_array($result))
						{
						$habit_name = $row['habitation_name'];
						$type_habit = $row['type_habit'];
						$glr = $row['glr'];
						$glsr = $row['glsr'];
						$cwr = $row['cwr'];
						$ohsr = $row['ohsr'];
						if($glr >0)
						{
							for($j=1; $j<=$glr; $j++)
							{ 
								 $i+=1;
							?>
				<tr align="center">
				<td width="180" align="center"><input type="text" name="type_reserv<?php echo $i;?>" id="type_reserv<?php echo $i;?>" value="<?php echo 'GLR'.$j;?>" size="20" class="txt4" readonly/></td>
					  <td width="182" align="center">
							<input type="text" name="habitation_name<?php echo $i;?>" id="habitation_name<?php echo $i;?>" value="<?php echo $habit_name;?>" size="20" class="txt4" readonly/>
				  <td align="center" width="95"><input type="text" name="type_habit<?php echo $i;?>" id="type_habit<?php echo $i;?>" value="<?php echo $type_habit;?>" size="2" class="txt_1" readonly/></td>
							<td width="117">
							<select size="1" name="status_reserv<?php echo $i;?>" id="status_reserv<?php echo $i;?>" class="txt5" >
                      		<option selected value="0">Select</option>
                     		 <?php 
								foreach($status_reserv as $key=>$val)
								{
		   							echo "<option value=\"$val\">$val</option>";
								}
							?>
       			  </select></td>
				  <td width="172"><input type="text" name="storege_cap<?php echo $i;?>" id="storege_cap<?php echo $i;?>" size="20" class="txt5" onBlur="float2dec(this)"></td>
				  <!--<td width="74"><input type="text" name="requirement<?php //echo $i;?>" id="requirement<?php //echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="drink_demand<?php //echo $i;?>" id="drink_demand<?php //echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="other_demand<?php //echo $i;?>" id="other_demand<?php //echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="total_demand<?php //echo $i;?>" id="total_demand<?php //echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				 <!-- <td width="70"><input type="text" name="lost_illegal<?php //echo $i;?>" id="lost_illegal<?php //echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="lost_leakage<?php //echo $i;?>" id="lost_leakage<?php //echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="ufw<?php //echo $i;?>" id="ufw<?php //echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="89"><input type="text" name="remark<?php //echo $i;?>" id="remark<?php //echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>-->
				  <?php 
					}
					}
					if($glsr >0)
						{
							for($j=1; $j<=$glsr; $j++)
							{ 
							$i+=1;
							?> 
			  </tr>
			  <tr align="center">
				<td width="180" align="center">
			    <input type="text" name="type_reserv<?php echo $i;?>" id="type_reserv<?php echo $i;?>" value="<?php echo 'GLSR'.$j;?>" size="20" class="txt4" readonly/></td>
					  <td width="182" align="center">
							<input type="text" name="habitation_name<?php echo $i;?>" id="habitation_name<?php echo $i;?>" value="<?php echo $habit_name;?>" size="20" class="txt4" readonly/>
			    <td align="center" width="95"><input type="text" name="type_habit<?php echo $i;?>" id="type_habit<?php echo $i;?>" value="<?php echo $type_habit;?>" size="2" class="txt_1" readonly/></td>
							<td width="117">
							<select size="1" name="status_reserv<?php echo $i;?>" id="status_reserv<?php echo $i;?>" class="txt5" >
                      		<option selected value="0">Select</option>
                     		 <?php 
								foreach($status_reserv as $key=>$val)
								{
		   							echo "<option value=\"$val\">$val</option>";
								}
							?>
   			    </select></td>
			    <td width="172"><input type="text" name="storege_cap<?php echo $i;?>" id="storege_cap<?php echo $i;?>" size="20" class="txt5" onBlur="float2dec(this)"></td>
				  <!--<td width="74"><input type="text" name="requirement<?php echo $i;?>" id="requirement<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="drink_demand<?php echo $i;?>" id="drink_demand<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="other_demand<?php echo $i;?>" id="other_demand<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="total_demand<?php echo $i;?>" id="total_demand<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <!--<td width="70"><input type="text" name="lost_illegal<?php //echo $i;?>" id="lost_illegal<?php //echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="lost_leakage<?php //echo $i;?>" id="lost_leakage<?php //echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="ufw<?php //echo $i;?>" id="ufw<?php //echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="89"><input type="text" name="remark<?php echo $i;?>" id="remark<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>-->
			  </tr>
			  <?php 
					}
					}
					if($cwr >0)
						{
							for($j=1; $j<=$cwr; $j++)
							{ 
							$i+=1;
							?>
			  <tr align="center">
				<td width="180" align="center">
			    <input type="text" name="type_reserv<?php echo $i;?>" id="type_reserv<?php echo $i;?>" value="<?php echo 'CWR'.$j;?>" size="20" class="txt4" readonly/></td>
					  <td width="182" align="center">
							<input type="text" name="habitation_name<?php echo $i;?>" id="habitation_name<?php echo $i;?>" value="<?php echo $habit_name;?>" size="20" class="txt4" readonly/>
			    <td align="center" width="95"><input type="text" name="type_habit<?php echo $i;?>" id="type_habit<?php echo $i;?>" value="<?php echo $type_habit;?>" size="2" class="txt_1" readonly/></td>
							<td width="117">
							<select size="1" name="status_reserv<?php echo $i;?>" id="status_reserv<?php echo $i;?>" class="txt5" >
                      		<option selected value="0">Select</option>
                     		 <?php 
								foreach($status_reserv as $key=>$val)
								{
		   							echo "<option value=\"$val\">$val</option>";
								}
							?>
   			    </select></td>
			    <td width="172"><input type="text" name="storege_cap<?php echo $i;?>" id="storege_cap<?php echo $i;?>" size="20" class="txt5" onBlur="float2dec(this)"></td>
				  <!--<td width="74"><input type="text" name="requirement<?php echo $i;?>" id="requirement<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="drink_demand<?php echo $i;?>" id="drink_demand<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="other_demand<?php echo $i;?>" id="other_demand<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="total_demand<?php echo $i;?>" id="total_demand<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				 <!-- <td width="70"><input type="text" name="lost_illegal<?php echo $i;?>" id="lost_illegal<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="lost_leakage<?php echo $i;?>" id="lost_leakage<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="ufw<?php echo $i;?>" id="ufw<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="89"><input type="text" name="remark<?php echo $i;?>" id="remark<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>-->
			  </tr>
			   <?php 
					}
					}
					if($ohsr >0)
						{
							for($j=1; $j<=$ohsr; $j++)
							{ 
							$i+=1;
							?>
			  <tr align="center">
				<td width="180" align="center">
			    <input type="text" name="type_reserv<?php echo $i;?>" id="type_reserv<?php echo $i;?>" value="<?php echo 'OHSR'.$j;?>" size="20" class="txt4" readonly/></td>
					  <td width="182" align="center">
							<input type="text" name="habitation_name<?php echo $i;?>" id="habitation_name<?php echo $i;?>" value="<?php echo $habit_name;?>" size="20" class="txt4" readonly/>
			    <td align="center" width="95"><input type="text" name="type_habit<?php echo $i;?>" id="type_habit<?php echo $i;?>" value="<?php echo $type_habit;?>" size="2" class="txt_1" readonly/></td>
							<td width="117">
							<select size="1" name="status_reserv<?php echo $i;?>" id="status_reserv<?php echo $i;?>" class="txt5" >
                      		<option selected value="0">Select</option>
                     		 <?php 
								foreach($status_reserv as $key=>$val)
								{
		   							echo "<option value=\"$val\">$val</option>";
								}
							?>
   			    </select></td>
			    <td width="172"><input type="text" name="storege_cap<?php echo $i;?>" id="storege_cap<?php echo $i;?>" size="20" class="txt5" onBlur="float2dec(this)"></td>
				  <!--<td width="74"><input type="text" name="requirement<?php echo $i;?>" id="requirement<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="drink_demand<?php echo $i;?>" id="drink_demand<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="other_demand<?php echo $i;?>" id="other_demand<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="total_demand<?php echo $i;?>" id="total_demand<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <!--<td width="70"><input type="text" name="lost_illegal<?php echo $i;?>" id="lost_illegal<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="lost_leakage<?php echo $i;?>" id="lost_leakage<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="70"><input type="text" name="ufw<?php echo $i;?>" id="ufw<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>
				  <td width="89"><input type="text" name="remark<?php echo $i;?>" id="remark<?php echo $i;?>" size="20" class="txt5" onKeyUp="float(this)"></td>-->
			  </tr>
			  <?php 
					}
					}
					//$k++;
				}
				?>
			  </table>
			  <input type="hidden" name="count_st_res" id="count_st_res" value="<?php echo $i;?>">			</td>
		</tr>
		<tr>
		  <td>&nbsp;</td>
	  </tr>
		
		
		<tr>
			<td align="center">
				<input type="submit" value="Click for Continue" name="submit" style="font-family: Verdana;">			</td>
		</tr>
</table>
</form>
</div>		
</body>
</html>
